package StuDemo.LinkedList;

import javax.swing.*;

/**
 * @Author: Dijah
 * @Date: 2022/12/15 10:24
 * @Desc: 反转链表
 */
public class code1_reverseLinkedList {



    //反转整个链表
    public ListNode reverse(ListNode head){

        //base case
        if(head == null || head.next == null){
            return head;
        }
        //递归
        ListNode last = reverse(head.next);
        head.next.next  = head;
        head.next = null;
        return last;

    }
}
